<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="listModalVisible"
    :confirm-loading="false"
    @ok="handleCancel"
    @cancel="handleCancel"
    cancelText="关闭"
    wrapClassName="map_Show"
  >
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <!--<a-col :md="6" :sm="8">
              <a-form-item label="贷款银行类型">
                <j-dict-select-tag placeholder="请选择贷款银行类型" v-model="queryParam.loanBankType" dictCode="bank_type"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="贷款银行">
                <a-input placeholder="请输入贷款银行" v-model="queryParam.loanBankId"></a-input>
              </a-form-item>
            </a-col>-->
           <!-- <a-col :md="6" :sm="8">
              <a-form-item label="业务号码">
                <a-input placeholder="请输入业务号码" v-model="queryParam.loanNumber"></a-input>
              </a-form-item>
            </a-col>-->
            <a-col :md="6" :sm="8">
              <a-form-item label="贷款用途">
                <a-input placeholder="请输入贷款用途" v-model="queryParam.loanUse"></a-input>
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="8">
              <a-form-item label="地区">
                <j-dict-select-tag placeholder="请选择地区" v-model="queryParam.fwzId"
                                   dictCode="tb_jrtx_fwz,township_name,id"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="身份证">
                <a-input placeholder="请输入身份证" v-model="queryParam.idNumber"></a-input>
              </a-form-item>
            </a-col>
            <template v-if="toggleSearchStatus">
            </template>
            <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--<a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>-->
            </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->

      <!-- 操作按钮区域 -->
      <!-- table区域-begin -->
      <div>
        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          @change="handleTableChange">
          <!-- 字符串超长截取省略号显示-->
          <span slot="loanNumber" slot-scope="text">
          <j-ellipsis :value="text" :length="10"/>
        </span>
          <!-- 字符串超长截取省略号显示-->
          <span slot="address" slot-scope="text">
          <j-ellipsis :value="text" :length="10"/>
        </span>
          <!-- 字符串超长截取省略号显示-->
          <span slot="loanUse" slot-scope="text">
          <j-ellipsis :value="text" :length="6"/>
        </span>
          <template slot="imgSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
            <img v-else :src="getImgView(text)" height="25px" alt="图片不存在"
                 style="max-width:80px;font-size: 12px;font-style: italic;"/>
          </template>
          <template slot="fileSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
            <a-button
              v-else
              :ghost="true"
              type="primary"
              icon="download"
              size="small"
              @click="uploadFile(text)">
              下载
            </a-button>
          </template>
        </a-table>
      </div>
    </a-card>
  </a-modal>
</template>

<script>
    import {deleteAction, getAction, downFile} from '@/api/manage'
    import {JeecgListMixin} from '@/mixins/JeecgListMixin'
    import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
    import {initDictOptions, filterMultiDictText} from '@/components/dict/JDictSelectUtil'
    import {filterObj} from '@/utils/util';
    import JEllipsis from "../../../components/jeecg/JEllipsis";

    export default {
        name: "HuDaiHuYongModal",
        mixins: [JeecgListMixin],
        components: {
            JEllipsis,
            JDictSelectTag,
        },
        data() {
            return {
                title: "户贷户用管理页面",
                listModalVisible: false,
                width: 1500,
                visible: false,
                description: '户贷户用管理页面',
                // 表头
                columns: [
                    /*{
                      title: '#',
                      dataIndex: '',
                      key:'rowIndex',
                      width:60,
                      align:"center",
                      customRender:function (t,r,index) {
                        return parseInt(index)+1;
                      }
                    },*/

                    {
                        title: '业务号码',
                        align: "center",
                        dataIndex: 'loanNumber',
                        scopedSlots: {customRender: 'loanNumber'},
                    },
                    {
                        title: '贷款人',
                        align: "center",
                        dataIndex: 'loanName'
                    },
                    {
                        title: '身份证号',
                        align: "center",
                        dataIndex: 'idNumber',
                    },
                    {
                        title: '乡镇',
                        align: "center",
                        dataIndex: 'fwzId',
                        customRender: (text) => {
                            if (!text) {
                                return ''
                            } else {
                                return filterMultiDictText(this.dictOptions['fwzId'], text + "")
                            }
                        }
                    },
                    {
                        title: '地址',
                        align: "center",
                        dataIndex: 'address',
                        scopedSlots: {customRender: 'address'},
                    },
                    {
                        title: '银行类型',
                        align: "center",
                        dataIndex: 'loanBankType',
                        customRender: (text) => {
                            if (!text) {
                                return ''
                            } else {
                                return filterMultiDictText(this.dictOptions['loanBankType'], text + "")
                            }
                        }
                    },
                    {
                        title: '贷款金额',
                        align: "center",
                        dataIndex: 'loanMoney'
                    },
                    {
                        title: '银行名称',
                        align: "center",
                        dataIndex: 'loanBankId',
                    },
                    {
                        title: '借款日',
                        align: "center",
                        dataIndex: 'borrowingDate',
                        customRender: function (text) {
                            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
                        }
                    },
                    {
                        title: '贷款用途',
                        align: "center",
                        dataIndex: 'loanUse',
                        scopedSlots: {customRender: 'loanUse'},
                    },

                    /* {
                       title: '操作',
                       dataIndex: 'action',
                       align:"center",
                       scopedSlots: { customRender: 'action' },
                     }*/
                ],
                url: {
                    list: "/common/daping/huDaiHuYongTanDetail",
                },
                dictOptions: {
                    fwzId: [],
                    loanBankType: [],
                    loanBankName: [],
                    loanUse: [],
                    isLoanInsurance: [],
                    isEvaluation: [],
                    loanType: [],
                    loanMode: [],
                }
            }
        },
        computed: {
            importExcelUrl: function () {
                return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
            }
        },
        methods: {
            loadData(arg) {
                console.log(this)
                if (!this.url.list) {
                    this.$message.error("请设置url.list属性!")
                    return
                }
                //加载数据 若传入参数1则加载第一页的内容
                if (arg === 1) {
                    this.ipagination.current = 1;
                }
                var params = this.getQueryParams();//查询条件
                this.loading = true;
                getAction(this.url.list, params).then((res) => {
                    if (res.success) {
                        this.dataSource = res.result.records;
                        this.ipagination.total = res.result.total;
                    }
                    if (res.code === 510) {
                        this.$message.warning(res.message)
                    }
                    this.loading = false;
                })
            },
            showGoodsGallery(record) {
                this.loadData(1);
                this.id = record.id;
                this.listModalVisible = true
            },
            handleCancel() {
                this.listModalVisible = false;
            },
            /*getQueryParams() {
                //获取查询条件
                let sqp = {}
                if(this.superQueryParams){
                    sqp['superQueryParams']=encodeURI(this.superQueryParams)
                }
                var param = Object.assign(sqp, this.queryParam, this.isorter ,this.filters);
                param.field = this.getQueryField();
                param.pageNo = this.ipagination.current;
                param.pageSize = this.ipagination.pageSize;
                if (param.idNumber!=undefined) {
                    param.idNumber = "*" + param.idNumber + "*";
                }
                return filterObj(param);
            },*/
            initDictConfig() {
                initDictOptions('tb_jrtx_fwz,township_name,id').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'fwzId', res.result)
                    }
                })
                initDictOptions('bank_type').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'loanBankType', res.result)
                    }
                })
                initDictOptions('tb_dict_bank,bank_name,id').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'loanBankName', res.result)
                    }
                })
                initDictOptions('loan_use').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'loanUse', res.result)
                    }
                })
                initDictOptions('is_loan_insurance').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'isLoanInsurance', res.result)
                    }
                })
                initDictOptions('is_evaluation').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'isEvaluation', res.result)
                    }
                })
                initDictOptions('loan_type').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'loanType', res.result)
                    }
                })
                initDictOptions('loan_mode').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'loanMode', res.result)
                    }
                })
            }

        }
    }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>